import { apiAllBalanceList } from '../../api/index'
import { formatTime } from '../../common/js/timer'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    myBalance: [],
    params: {
      page_index: 1,
      page_size: 15,
      loads: true
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.getMyBalance()
    this.setData({
      isIphoneX: getApp().globalData.isIphoneX
    })
  },
  getMyBalance () {
    apiAllBalanceList(this.data.params).then(
      res => {
        for (let i = 0; i < res.data.data.length; i++) {
          res.data.data[i].create_time = formatTime(res.data.data[i].create_time, 'Y-M-D h:m:s')
        }
        let data = this.data.myBalance
        this.setData({
          myBalance: data.concat(res.data.data),
          loads: false
        })
        wx.stopPullDownRefresh()
      }
    )
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () {
    if (this.data.myBalance.length === 0) {
      wx.stopPullDownRefresh()
    }
    this.data.params['page_index'] = 1
    this.setData({
      myBalance: []
    })
    this.getMyBalance()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () {
    // if (this.data.isMore) {
    this.data.params['page_index']++
    this.getMyBalance()
    // }
  }
})
